using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.Circle;
using MicroMsg.Plugin.FaceBook;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.Page
{
	public class SettingMainPage : BasePage
	{
		private const string TAG = "SettingMainPage";
		private bool isShowMore;
		private EventWatcher m_HeadImageSyncOK;
		private EventWatcher m_GetVersionOK;
		private EventWatcher m_GetVersionErr;
		private UpdateInfo m_UpdateInfo;
		private EventWatcher mWatcherLogOut;
		private string mStrSigOrigin = "";
		internal Grid LayoutRoot;
		internal Grid ContentPanel;
		internal Grid MainLayout;
		internal TextBlock txtLogoTitle;
		internal Canvas btnHeadLayout1;
		internal Image imgHead;
		internal EmojiText txtName;
		internal Button btnHeadLayout;
		internal Button btnSignature;
		internal TextBlock txtSignature;
		internal ClickableLayout btnQRCode;
		internal ClickableLayout btnMyAlbum;
		internal ClickableLayout btnAccountInfo;
		internal ClickableLayout btnCommonSetting;
		internal ClickableLayout btnPluginSetting;
		internal ClickableLayout btnPrivateSetting;
		internal TextBlock txtVersion;
		internal ClickableLayout btnGotoReviews;
		internal ClickableLayout btnFAQ;
		internal ClickableLayout btnFeedback;
		internal ClickableLayout btnMore;
		internal Grid MoreLayout;
		internal ClickableLayout btnChatBackground;
		internal TextBlock txtChatBackground;
		internal ClickableLayout btnNetFlowControl;
		internal TextBlock txtNetFlowControl;
		internal ClickableLayout btnLikeOnFacabook;
		internal ClickableLayout btnFollowOnTwitter;
		internal ClickableLayout btnVersion;
		internal Image imgHasNewVersion;
		internal ClickableLayout btnClearChat;
		internal ClickableLayout btnLogout;
		private bool _contentLoaded;
		public SettingMainPage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.onPageLoaded));
			base.add_Unloaded(new RoutedEventHandler(this.doFinish));
		}
		private void doFinish(object sender, RoutedEventArgs e)
		{
			if (this.m_HeadImageSyncOK == null)
			{
				return;
			}
			EventCenter.removeEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.m_HeadImageSyncOK);
			this.m_HeadImageSyncOK = null;
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_UPDATE_INFO_SUCCESS, this.m_GetVersionOK);
			this.m_GetVersionOK = null;
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_UPDATE_INFO_ERR, this.m_GetVersionErr);
			this.m_GetVersionErr = null;
		}
		private void onPageLoaded(object sender, RoutedEventArgs e)
		{
			this.m_HeadImageSyncOK = new EventWatcher(this, null, new EventHandlerDelegate(this.onHeadImageSyncOK));
			EventCenter.registerEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.m_HeadImageSyncOK);
			this.m_GetVersionOK = new EventWatcher(this, null, new EventHandlerDelegate(this.onGetVersionOK));
			this.m_GetVersionErr = new EventWatcher(this, null, new EventHandlerDelegate(this.onGetVersionErr));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_UPDATE_INFO_SUCCESS, this.m_GetVersionOK);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_UPDATE_INFO_ERR, this.m_GetVersionErr);
			ServiceCenter.sceneGetUpdateInfo.doScene(UpdateType.UPDATETYPE_MANUAL);
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (!Util.isMarketVersion())
			{
				this.btnGotoReviews.set_Visibility(1);
			}
			if (!FaceBookMgr.IsChina())
			{
				this.btnLikeOnFacabook.set_Visibility(0);
				this.btnFollowOnTwitter.set_Visibility(0);
			}
			this.refreshView();
		}
		protected override void OnPageBack()
		{
			this.refreshView();
		}
		private void refreshView()
		{
			this.txtName.Text = this.trimToEmpty(AccountMgr.strNickName);
			BitmapImage headimg = AccountMgr.getHeadimg();
			if (headimg != null)
			{
				this.imgHead.set_Source(headimg);
			}
			SelfPersonCard selfPersonCard = AccountMgr.getSelfPersonCard();
			if (selfPersonCard != null)
			{
				this.txtSignature.set_Text(this.trimToEmpty(selfPersonCard.strSignature));
			}
			if (R.isChineseCN())
			{
				this.btnFeedback.set_Visibility(1);
				this.btnFAQ.set_Visibility(0);
				return;
			}
			this.btnFAQ.set_Visibility(1);
			this.btnFeedback.set_Visibility(0);
		}
		private void onGetVersionOK(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.m_UpdateInfo = (evtArgs.mObject as UpdateInfo);
			if (this.m_UpdateInfo != null)
			{
				this.imgHasNewVersion.set_Visibility(0);
			}
		}
		private void onGetVersionErr(EventWatcher watcher, BaseEventArgs evtArgs)
		{
		}
		private void onHeadImageSyncOK(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			List<object> list = evtArgs.mObject as List<object>;
			if (list != null || list.Contains(AccountMgr.curUserName))
			{
				BitmapImage headimg = AccountMgr.getHeadimg();
				if (headimg != null)
				{
					this.imgHead.set_Source(headimg);
				}
			}
		}
		protected override void OnPageOut()
		{
		}
		private string trimToEmpty(string string_0)
		{
			if (string_0 != null)
			{
				return string_0.Trim();
			}
			return "";
		}
		private void button_Click(object sender, RoutedEventArgs e)
		{
			if (sender == null)
			{
				return;
			}
			if (sender == this.btnMyAlbum)
			{
				Circle.getInstance().execute(5, null);
				return;
			}
			if (sender == this.btnHeadLayout)
			{
				base.GoToPage("/Source/UI/Setting/PersonalInfoView.xaml", null, false);
				return;
			}
			if (sender == this.btnQRCode)
			{
				base.GoToPage("/Source/Plugin/QRCode/UI/UserQRCodePage.xaml", null, false);
				return;
			}
			if (sender == this.btnAccountInfo)
			{
				base.GoToPage("/Source/UI/Setting/AccountSettingView.xaml", null, false);
				return;
			}
			if (sender == this.btnCommonSetting)
			{
				base.GoToPage("/Source/UI/Setting/CommonSettingView.xaml", null, false);
				return;
			}
			if (sender == this.btnPluginSetting)
			{
				base.GoToPage("/Source/UI/Setting/PluginListPage.xaml", null, false);
				return;
			}
			if (sender == this.btnPrivateSetting)
			{
				base.GoToPage("/Source/UI/Setting/PrivateSettingView.xaml", null, false);
				return;
			}
			if (sender == this.btnChatBackground)
			{
				ToolFunction.GotoPageForUserControl("/Source/UI/Chat/background/SetBackgroundPage.xaml", new object[]
				{
					"DEFAULT_BACKGROUND_USER_NAME"
				}, false);
				return;
			}
			if (sender == this.btnNetFlowControl)
			{
				base.GoToPage("/Source/UI/Setting/NetFlowPage.xaml", null, false);
				return;
			}
			if (sender == this.btnGotoReviews)
			{
				Util.gotoAppReviews();
				return;
			}
			if (sender == this.btnLikeOnFacabook)
			{
				Account curAccount = AccountMgr.getCurAccount();
				if (curAccount != null)
				{
					ToolFunction.GotoWebLink(string.Format("http://www.wechatapp.com/cgi-bin/readtemplate?t=client-redirect&to=facebook&uin={0}&device=5", curAccount.nUin));
				}
				return;
			}
			if (sender == this.btnFollowOnTwitter)
			{
				Account curAccount2 = AccountMgr.getCurAccount();
				if (curAccount2 != null)
				{
					ToolFunction.GotoWebLink(string.Format("http://www.wechatapp.com/cgi-bin/readtemplate?t=client-redirect&to=twitter&uin={0}&device=5", curAccount2.nUin));
				}
			}
			if (sender == this.btnFeedback)
			{
				base.GoToPage("/Source/UI/Setting/FeedBackPage.xaml", null, false);
				return;
			}
			if (sender == this.btnFAQ)
			{
				base.GoToPage("/Source/UI/Setting/FAQPage.xaml", null, false);
				return;
			}
			if (sender == this.btnVersion)
			{
				object[] object_ = new object[]
				{
					this.m_UpdateInfo
				};
				base.GoToPage("/Source/UI/Setting/AboutMMPage.xaml", object_, false);
				return;
			}
			if (sender == this.btnClearChat)
			{
				this.txtClearData_Click(sender, e);
				return;
			}
			if (sender == this.btnLogout)
			{
				this.initLogOut();
				return;
			}
			if (sender == this.btnMore)
			{
				if (this.isShowMore)
				{
					return;
				}
				this.isShowMore = true;
				this.MainLayout.set_Visibility(1);
				this.MoreLayout.set_Visibility(0);
			}
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			if (this.isShowMore)
			{
				this.isShowMore = false;
				this.MoreLayout.set_Visibility(1);
				this.MainLayout.set_Visibility(0);
				cancelEventArgs_0.set_Cancel(true);
			}
		}
		private DoubleAnimation createAnimation(double from, double double_0, UIElement target, string property, uint duration)
		{
			new Storyboard();
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(new double?(from));
			doubleAnimation.set_To(new double?(double_0));
			doubleAnimation.set_Duration(TimeSpan.FromMilliseconds(duration));
			Storyboard.SetTarget(doubleAnimation, target);
			Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(property, new object[0]));
			return doubleAnimation;
		}
		private void txtClearData_Click(object sender, RoutedEventArgs e)
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Set_Main_ClearRecord, strings.Set_Main_ClearRecordWarning, true, strings.COM_Confirm, strings.COM_Cancel);
			mMMessageBox.set_FontSize(22.0);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.MsgBoxClearDataHandler);
		}
		private void showHDImage(object sender, RoutedEventArgs e)
		{
			base.GoToPage("/Source/UI/Setting/HighQualityHeadImgPage.xaml", new object[]
			{
				this.imgHead.get_Source(),
				AccountMgr.curUserName,
				68.0
			}, false);
		}
		public void MsgBoxClearDataHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.showProgressCover("");
				base.get_Dispatcher().BeginInvoke(delegate
				{
					ChatMsgMgr.ClearAllMsg();
					this.hideProgressCover();
				});
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		public static string GetShowVersion(uint version)
		{
			if (version == 0u)
			{
				return "";
			}
			uint num = (version & 251658240u) >> 24;
			uint num2 = (version & 1044480u) >> 12;
			return num + "." + num2;
		}
		private void initLogOut()
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Set_Main_Logout, strings.Set_Main_LogoutWarning, true, strings.COM_Confirm, strings.COM_Cancel);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.logoutMsgBoxHandler);
		}
		private void doInitLoOut()
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.Set_Main_Logouting, null, false, false, null);
			this.mWatcherLogOut = new EventWatcher(null, null, new EventHandlerDelegate(this.onInitLogOutDone));
			FaceBookMgr.ForceTokenExpires();
			FaceBookMgr.SetIsFacebookAccountChanged(true);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_LOGOUT_OVER, this.mWatcherLogOut);
			ServiceCenter.sceneLogout.doScene();
		}
		private void logoutMsgBoxHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.doInitLoOut();
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		private void onInitLogOutDone(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			ProcessingCover.releaseProgressBar(MainPage.mainPageInstance.LayoutRoot);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_LOGOUT_OVER, this.mWatcherLogOut);
			this.mWatcherLogOut = null;
			MainPage.logOut();
		}
		private void txtSignature_Click(object sender, RoutedEventArgs e)
		{
			string text = this.trimToEmpty(AccountMgr.getSelfPersonCard().strSignature);
			this.mStrSigOrigin = text;
			Dialog2BtnWithInputBox dialog2BtnWithInputBox = Dialog2BtnWithInputBox.Show(strings.Set_Main_InputSignature, "", strings.COM_Confirm, strings.COM_Cancel, "", new Dialog2BtnWithInputBox.dismissWithClickBtn(this.saveSignature), new TextChangedEventHandler(this.signatureChangedHandler), text);
			dialog2BtnWithInputBox.txtIn.set_SelectionStart(text.get_Length());
		}
		private void saveSignature(object sender, int nClickIndex)
		{
			if (nClickIndex == 0 && sender != null && sender is Dialog2BtnWithInputBox)
			{
				Dialog2BtnWithInputBox dialog2BtnWithInputBox = sender as Dialog2BtnWithInputBox;
				string text = dialog2BtnWithInputBox.txtIn.get_Text();
				SelfPersonCard selfPersonCard = AccountMgr.getSelfPersonCard();
				if (selfPersonCard != null)
				{
					selfPersonCard.strSignature = this.trimToEmpty(text);
					AccountMgr.setSelfPersonCard(selfPersonCard);
					this.txtSignature.set_Text(text);
					Contact contact = StorageMgr.contact.method_0(AccountMgr.curUserName);
					if (contact != null)
					{
						contact.strSignature = text;
						StorageMgr.contact.modify(contact);
					}
				}
			}
		}
		private void signatureChangedHandler(object sender, TextChangedEventArgs e)
		{
			if (sender != null && sender is Dialog2BtnWithInputBox)
			{
				Dialog2BtnWithInputBox dialog2BtnWithInputBox = sender as Dialog2BtnWithInputBox;
				if (ToolFunction.getStrDisLen(dialog2BtnWithInputBox.txtIn.get_Text()) <= 60)
				{
					dialog2BtnWithInputBox.btnLeft.set_IsEnabled(true);
					int arg_48_0 = dialog2BtnWithInputBox.txtContent.get_Text().get_Length();
					this.mStrSigOrigin = dialog2BtnWithInputBox.txtIn.get_Text();
					return;
				}
				if (this.mStrSigOrigin != null && this.mStrSigOrigin.get_Length() < dialog2BtnWithInputBox.txtIn.get_Text().get_Length())
				{
					dialog2BtnWithInputBox.txtIn.set_Text(this.mStrSigOrigin);
					dialog2BtnWithInputBox.txtIn.set_SelectionStart(dialog2BtnWithInputBox.txtIn.get_Text().get_Length());
				}
				this.mStrSigOrigin = dialog2BtnWithInputBox.txtIn.get_Text();
				dialog2BtnWithInputBox.txtContent.set_Text(strings.Set_Main_SignatureTooLong);
			}
		}
		private void showProgressCover(string strCoverTitle)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strCoverTitle, (SolidColorBrush)Application.get_Current().get_Resources().get_Item("HalfOpacityBrush1"), false, false, null);
		}
		private void hideProgressCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Setting/SettingMainPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.MainLayout = (Grid)base.FindName("MainLayout");
			this.txtLogoTitle = (TextBlock)base.FindName("txtLogoTitle");
			this.btnHeadLayout1 = (Canvas)base.FindName("btnHeadLayout1");
			this.imgHead = (Image)base.FindName("imgHead");
			this.txtName = (EmojiText)base.FindName("txtName");
			this.btnHeadLayout = (Button)base.FindName("btnHeadLayout");
			this.btnSignature = (Button)base.FindName("btnSignature");
			this.txtSignature = (TextBlock)base.FindName("txtSignature");
			this.btnQRCode = (ClickableLayout)base.FindName("btnQRCode");
			this.btnMyAlbum = (ClickableLayout)base.FindName("btnMyAlbum");
			this.btnAccountInfo = (ClickableLayout)base.FindName("btnAccountInfo");
			this.btnCommonSetting = (ClickableLayout)base.FindName("btnCommonSetting");
			this.btnPluginSetting = (ClickableLayout)base.FindName("btnPluginSetting");
			this.btnPrivateSetting = (ClickableLayout)base.FindName("btnPrivateSetting");
			this.txtVersion = (TextBlock)base.FindName("txtVersion");
			this.btnGotoReviews = (ClickableLayout)base.FindName("btnGotoReviews");
			this.btnFAQ = (ClickableLayout)base.FindName("btnFAQ");
			this.btnFeedback = (ClickableLayout)base.FindName("btnFeedback");
			this.btnMore = (ClickableLayout)base.FindName("btnMore");
			this.MoreLayout = (Grid)base.FindName("MoreLayout");
			this.btnChatBackground = (ClickableLayout)base.FindName("btnChatBackground");
			this.txtChatBackground = (TextBlock)base.FindName("txtChatBackground");
			this.btnNetFlowControl = (ClickableLayout)base.FindName("btnNetFlowControl");
			this.txtNetFlowControl = (TextBlock)base.FindName("txtNetFlowControl");
			this.btnLikeOnFacabook = (ClickableLayout)base.FindName("btnLikeOnFacabook");
			this.btnFollowOnTwitter = (ClickableLayout)base.FindName("btnFollowOnTwitter");
			this.btnVersion = (ClickableLayout)base.FindName("btnVersion");
			this.imgHasNewVersion = (Image)base.FindName("imgHasNewVersion");
			this.btnClearChat = (ClickableLayout)base.FindName("btnClearChat");
			this.btnLogout = (ClickableLayout)base.FindName("btnLogout");
		}
	}
}
